/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.*;

import javax.servlet.http.*;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.sesame.domain.Album;
import com.sesame.domain.Image;
import com.sesame.domain.User;
import com.sesame.service.AlbumService;
import com.sesame.service.SearchService;
import com.sesame.toolkit.Encrypt;

/**
 * @author voidman
 * 
 */
public class SearchAlbumTagController extends AbstractController {
    private AlbumService albumService;

    public void setAlbumService(AlbumService albumService) {
        this.albumService = albumService;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        String q = request.getParameter("q");

        if (q == null) {
            return new ModelAndView("redirect:guestHome.html");

        } else {

            List<Album> albumList = albumService.searchAlbumTag(q);

            Map model = new HashMap();

            for (Album album : albumList) {
                if (!album.getPrivacy().equals("0"))
                    album.setCover(Encrypt.MapEncrypt("00000/001"));

            }
            model.put("albumList", albumList);

            model.put("q", q);

            return new ModelAndView("searchAlbumTag", model);
        }

    }
}